#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
    int n = people.size();
    sort(people.begin(), people.end(), [](vector<int>& p1, vector<int>& p2) {
        return p1[0] > p2[0] || (p1[0] == p2[0] && p1[1] < p2[1]);
        });

    vector<vector<int>> res;
    for (auto p : people)
        res.insert(res.begin() + p[1], p);
    return res;
}